<%--
  Created by IntelliJ IDEA.
  User: 11076
  Date: 2018/11/22
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <%--<base href="<%=basePath%>">--%>
    <title>Title</title>
    <%--<link rel="stylesheet" href="static/dataTable/css/bootstrap.min.css" />--%>
    <%--<link rel="stylesheet" href="static/dataTable/css/dataTables.bootstrap.css" />--%>

    <%--<script type="text/javascript" src="static/dataTable/js/jquery-3.3.1.min.js"></script>--%>
    <%--<script type="text/javascript" src="static/dataTable/js/bootstrap.min.js"></script>--%>
    <%--<script type="text/javascript" src="static/dataTable/js/jquery.dataTables.js"></script>--%>
    <%--<script type="text/javascript" src="static/dataTable/js/dataTables.bootstrap.js"></script>--%>

    <%--&lt;%&ndash;弹出框&ndash;%&gt;--%>
    <%--<link type="text/css" rel="stylesheet" href="plugins/attention/drag/style.css">--%>
    <%--<script type="text/javascript" src="plugins/attention/drag/drag.js"></script>--%>
    <%--<script type="text/javascript" src="plugins/attention/drag/dialog.js"></script>--%>
    <%@ include file="../base/top.jsp" %>


    <style>
        #result_admin{
            width: 90%;
            margin: auto;
            margin-top: 20px;
            padding: 20px;
            box-shadow: 0px 0px 3px #888888 ;
            border-radius: 5px;
            background-color: #FFFFFF;
        }
        .modal-dialog{
            z-index: 9999;
        }
        .error{
            color: red;
            display: none;
        }
    </style>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-sm-6 col-sm-offset-3 col-xs-12" id="pw-form">
                        <div class="form-group">
                            <label for="uer-id">用户账号</label>
                            <input type="text" name="userId" class="form-control" id="uer-id" placeholder="${userId}" readonly>
                        </div>
                        <div class="form-group">
                            <label for="old-password">原始密码</label>
                            <input type="password" name="oldPassword" class="form-control" id="old-password" placeholder="原始密码">
                            <p id="error1" class="error">*密码不能为空</p>
                            <p id="error2" class="error">*密码为6-16为字母数字</p>
                        </div>
                        <div class="form-group">
                            <label for="new-password" id="new-password-label">新密码</label>
                            <input type="password" name="newPassword" class="form-control" id="new-password" placeholder="新密码">
                            <p id="error3" class="error">*密码不能为空</p>
                            <p id="error4" class="error">*密码为6-16为字母数字</p>
                            <p id="error5" class="error">*新密码不能和原始密码一样啊</p>
                        </div>
                        <div class="form-group">
                            <label for="new-password-again" id="password-again-label">再次输入新密码</label>
                            <input type="password" name="newPasswordAgain" class="form-control" id="new-password-again" placeholder="再次输入新密码">
                            <p id="error6" class="error">*密码不能为空</p>
                            <p id="error7" class="error">*两次输入的新密码不一致</p>
                        </div>
                        <div class="center">
                            <button class="btn btn-success" id="save-btn">保存</button>
                            <button class="btn btn-danger" id="reset">重置</button>
                        </div>
                    </div>
                    <!-- /.col -->
                </div>

                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

</div>
<%@ include file="../base/foot.jsp" %>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
<script src="static/js/common/format-tips.js"></script>
<script>
    function checkFormats() {
        if($("#old-password").val()==null || $("#old-password").val()==""){
            $("#error1").show();
            $("#old-password").focus();
            return false;
        }else{
            if(!checkRegex($("#old-password").val())){
                $("#error2").show();
                $("#old-password").focus();
                return false;
            }
        }
        if($("#new-password").val()==null || $("#new-password").val()==""){
            $("#error3").show();
            $("#new-password").focus();
            return false;
        }else{
            if(!checkRegex($("#new-password").val())){
                $("#error4").show();
                $("#new-password").focus();
                return false;
            }
            if($("#old-password").val()==$("#new-password").val()) {
                $("#error5").show();
                $("#new-password").focus();
                return false;
            }
        }
        if($("#new-password-again").val()==null || $("#new-password-again").val()==""){
            $("#error6").show();
            $("#new-password-again").focus();
            return false;
        }else {
            if($("#new-password-again").val()!=$("#new-password").val()) {
                $("#error7").show();
                $("#new-password-again").focus();
                return false;
            }
        }
        return true;
    }
    function checkRegex(password) {
        var regex =/^[A-Za-z0-9]{6,16}$/;
        return regex.test(password);
    }

    $("#save-btn").click(function () {
        if(checkFormats()){
            var data = {};
            data.oldPassword = $("#old-password").val();
            data.newPassword = $("#new-password").val();
            $.ajax({
                type:"post",
                url:"<%= basePath%>user/editPassword",
                data:data,
                success:function (data) {
                    if(data["success"]==true){
                        prompt_alert('success',"操作成功",0);;
                    }else{
                        prompt_alert('error',"更新失败",0);;
                    }
                }
            })
        }
    });

    $("#reset").click(function () {
        $("#old-password").val("");
        $("#new-password").val("");
        $("#new-password-again").val("");
    })

    $("#pw-form").on('input propertychange',function () {
        $(".error").hide();
    });

</script>

</body>
</html>
